package cn.gok.springsecuritydemo4.dao;

import cn.gok.springsecuritydemo4.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author: chen fan
 * @since: 2022/11/22 15:33
 * @description:
 */
public interface RoleDAO extends BaseMapper<Role> {

    @Select("SELECT tr.* FROM t_user tu LEFT JOIN t_user_role tur ON tu.id = tur.UID " +
            "LEFT JOIN t_role tr ON tur.RID = tr.ID WHERE tu.username = #{userName }")
    List<Role> findRolesByUserName(String userName);


    @Select("SELECT tr.* FROM t_permission tp LEFT JOIN t_role_permission trp ON tp.ID = trp.PID " +
            "LEFT JOIN t_role tr ON trp.RID = tr.ID WHERE tp.ID = #{permissionId}")
    List<Role> findRolesByPermissionId(Integer permissionId);
}
